package com.clear.honghefinance.admin.controller;

import com.clear.honghefinance.biz.modules.voucher.domain.dto.CreateVoucherWordConfigDTO;
import com.clear.honghefinance.biz.modules.voucher.domain.dto.DeleteVoucherWordConfigDTO;
import com.clear.honghefinance.biz.modules.voucher.domain.dto.UpdateVoucherWordConfigDTO;
import com.clear.honghefinance.biz.modules.voucher.domain.dto.UpdateVoucherWordConfigDefaultFlagDTO;
import com.clear.honghefinance.biz.modules.voucher.domain.vo.GetVoucherWordConfigDetailVO;
import com.clear.honghefinance.biz.modules.voucher.domain.vo.ListVoucherWordConfigVO;
import com.clear.honghefinance.biz.modules.voucher.service.IVoucherWordConfigService;
import com.clear.honghefinance.common.dto.entity.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 凭证字设置Controller
 */
@Api(tags = "凭证字设置")
@RestController
@RequestMapping(value = "/voucherWordConfig")
@Slf4j
@RequiredArgsConstructor
public class VoucherWordConfigController {
    private final IVoucherWordConfigService voucherWordConfigService;

    /**
     * 添加凭证字
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "添加凭证字")
    @PostMapping(value = "/create")
    public ApiResponse<Boolean> create(@Validated @RequestBody CreateVoucherWordConfigDTO dto) {
        return ApiResponse.success(voucherWordConfigService.create(dto));
    }

    /**
     * 创建凭证字
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "修改凭证字")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Validated @RequestBody UpdateVoucherWordConfigDTO dto) {
        return ApiResponse.success(voucherWordConfigService.update(dto));
    }

    /**
     * 修改默认凭证字
     * @param dto
     * @return
     */
    @ApiOperation(value = "修改默认凭证字")
    @PostMapping(value = "/updateDefaultFlag")
    public ApiResponse<Boolean> updateDefaultFlag(@Valid @RequestBody UpdateVoucherWordConfigDefaultFlagDTO dto) {
        return ApiResponse.success(voucherWordConfigService.updateDefaultFlag(dto));
    }


    /**
     * 删除凭证字
     *
     * @param dto req
     * @return
     */
    @ApiOperation(value = "删除凭证字")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> del(@Validated @RequestBody DeleteVoucherWordConfigDTO dto) {
        return ApiResponse.success(voucherWordConfigService.delete(dto));
    }


    /**
     * 查询凭证字列表（暂不需要分页）
     *
     * @return
     */
    @ApiOperation(value = "查询凭证字列表")
    @GetMapping(value = "/list")
    public ApiResponse<List<ListVoucherWordConfigVO>> list() {
        return ApiResponse.success(voucherWordConfigService.listAll());
    }


    /**
     * 查询凭证字列表
     *
     * @param id 凭证字id
     * @return
     */
    @ApiOperation(value = "获取凭证字详情")
    @GetMapping(value = "/get")
    public ApiResponse<GetVoucherWordConfigDetailVO> get(@Validated @NotNull(message = "凭证字id不能为空")
                                                   @Min(value = 1) @RequestParam long id) {
        return ApiResponse.success(voucherWordConfigService.getDetailById(id));
    }
}

